package com.myl.service;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import com.myl.bean.User;
import com.myl.mapper.UseMapper;

public class UserServiceImp implements UserService{

	@Override
	public List<User> login(User user) {
		InputStream inputStream = null;
		SqlSession sqlSession =null;
		List<User> list = null;
		try {
			 inputStream = Resources.getResourceAsStream("MyBatisConfig.xml");
			SqlSessionFactory sessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
			 sqlSession = sessionFactory.openSession(true);
			UseMapper mapper = sqlSession.getMapper(UseMapper.class);
			 list = mapper.login(user);

		} catch (Exception e) {
			e.printStackTrace();
		}finally {
			if(sqlSession!=null){
				sqlSession.close();
			}
			if(inputStream!=null){
				try {
					inputStream.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}
		return list;
	}

	
}
